package cn.iocoder.yudao.module.wine.controller.admin.countnameconfig;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.countnameconfig.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.countnameconfig.CountNameConfigDO;
import cn.iocoder.yudao.module.wine.service.countnameconfig.CountNameConfigService;

@Tag(name = "管理后台 - 统计名称配置")
@RestController
@RequestMapping("/wine/count-name-config")
@Validated
public class CountNameConfigController {

    @Resource
    private CountNameConfigService countNameConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建统计名称配置")
    @PreAuthorize("@ss.hasPermission('wine:count-name-config:create')")
    public CommonResult<Long> createCountNameConfig(@Valid @RequestBody CountNameConfigSaveReqVO createReqVO) {
        return success(countNameConfigService.createCountNameConfig(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新统计名称配置")
    @PreAuthorize("@ss.hasPermission('wine:count-name-config:update')")
    public CommonResult<Boolean> updateCountNameConfig(@Valid @RequestBody CountNameConfigSaveReqVO updateReqVO) {
        countNameConfigService.updateCountNameConfig(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除统计名称配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:count-name-config:delete')")
    public CommonResult<Boolean> deleteCountNameConfig(@RequestParam("id") Long id) {
        countNameConfigService.deleteCountNameConfig(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得统计名称配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:count-name-config:query')")
    public CommonResult<CountNameConfigRespVO> getCountNameConfig(@RequestParam("id") Long id) {
        CountNameConfigDO countNameConfig = countNameConfigService.getCountNameConfig(id);
        return success(BeanUtils.toBean(countNameConfig, CountNameConfigRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得统计名称配置分页")
    @PreAuthorize("@ss.hasPermission('wine:count-name-config:query')")
    public CommonResult<PageResult<CountNameConfigRespVO>> getCountNameConfigPage(@Valid CountNameConfigPageReqVO pageReqVO) {
        PageResult<CountNameConfigRespVO> pageResult = countNameConfigService.getCountNameConfigPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出统计名称配置 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:count-name-config:export')")
//    @OperateLog(type = EXPORT)
//    public void exportCountNameConfigExcel(@Valid CountNameConfigPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CountNameConfigDO> list = countNameConfigService.getCountNameConfigPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "统计名称配置.xls", "数据", CountNameConfigRespVO.class,
//                        BeanUtils.toBean(list, CountNameConfigRespVO.class));
//    }

}
